#include "Vertex3d.h"
#include <math.h>

Vertex3d::Vertex3d()
: m_v1(0), m_v2(0), m_v3(0)
{

}
Vertex3d::Vertex3d(const Vertex3d &vert)
: m_v1(vert.m_v1),
m_v2(vert.m_v2),
m_v3(vert.m_v3)
{

}
Vertex3d::Vertex3d(double v1, double v2, double v3)
: m_v1(v1), m_v2(v2), m_v3(v3)
{

}

void Vertex3d::Normal()
{
    double s = sqrt(m_v1*m_v1+m_v2*m_v2+m_v3*m_v3);
    m_v1 /= s;
    m_v2 /= s;
    m_v3 /= s;
}

double Vertex3d::DotMul(const Vertex3d &vert)
{
    return m_v1*vert.m_v1 + m_v2*vert.m_v2 + m_v3*vert.m_v3;     
}

void Vertex3d::CrossMul(const Vertex3d &vert)
{
   double v1 = -m_v3*vert.m_v2 + m_v2*vert.m_v3;
   double v2 = m_v3*vert.m_v1 - m_v1*vert.m_v3;
   double v3 = -m_v2*vert.m_v1 + m_v1*vert.m_v2;

   m_v1 = v1;
   m_v2 = v2;
   m_v3 = v3;
}